import { GetAreaService } from './../../../shared/get-area.service';
import { Component, OnInit } from '@angular/core';
import { MyModalComponent } from '../my-modal/my-modal.component';
import { NzModalService } from 'ng-zorro-antd';
import { IndexDbService } from 'src/app/shared/index-db.service';

@Component({
  selector: 'jk-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
  areaList: any;
  list;
  data;
  constructor(private modalService: NzModalService, private area: GetAreaService, private indexDB: IndexDbService) { }

  ngOnInit() {
    this.area.getArea().then(res => {
      this.areaList = res;
    });
    this.indexDB.initDB(['test1', 'test2']);
  }

  createComponentModal(): void {
    const modal = this.modalService.create({
      nzTitle: 'Modal Title',
      nzContent: MyModalComponent,
      nzComponentParams: {
        // title: 'title in component',
        // subtitle: 'component sub title，will be changed after 2 sec'
      },
      nzFooter: [{
        label: 'change component tilte from outside',
        onClick: (componentInstance) => {
          // componentInstance.title = 'title in inner component is changed';
        }
      }]
    });
  }

  search() {
    this.indexDB.getData('user2', 'defult').then(e => {
      this.list = e;
      console.log(this.list);
    });
    this.indexDB.getData('user', 'defult').then(e => {
      this.data = e;
      console.log(this.data);
    });
  }
  save() {
    this.indexDB.setData('user', 'defult', {
      id: 1,
      name: '张三',
      age: 24,
      email: 'zhangsan@example.com',
      test: 's'
    });
  }

  edit() {
    this.indexDB.setData('user2', 'defult', [{
      id: 1,
      name: '李四',
      age: 28,
      email: 'lisi@example.com'
    }]);
  }
  del() {
    this.indexDB.setData('user', 'defult');
  }
  clearStore() {
    this.indexDB.clearStore('defult');
  }
  clearDatabase() {
    this.indexDB.deleteDB('DBName');
  }
}
